package com.wangjiyuan.shiwupai.ui.activity.photo;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.wangjiyuan.shiwupai.R;
import com.wangjiyuan.shiwupai.base.BaseApplication;
import com.wangjiyuan.shiwupai.bean.guangchi.photo.PhotoBean;

public class PhotoActivity extends AppCompatActivity implements PhotoContract.PhotoView {
    private TextView user_name, agree, time;
    private ImageView user_avatar, image_url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        initView();


    }

    private void initView() {
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        image_url = (ImageView) findViewById(R.id.image_url);
        user_avatar = (ImageView) findViewById(R.id.user_avatar);
        user_name = (TextView) findViewById(R.id.user_name);
        agree = (TextView) findViewById(R.id.agree);
        time = (TextView) findViewById(R.id.time);
        String id = getIntent().getStringExtra("id");
        PhotoPresenter presenter = new PhotoPresenter(this);
        presenter.getPhoto(id);
    }

    @Override
    public void getPhoto(PhotoBean bean) {
        ViewGroup.LayoutParams layoutParams = image_url.getLayoutParams();
        layoutParams.width = BaseApplication.width;
        layoutParams.height = layoutParams.width * 4 / 3;
        Glide.with(this)
                .load(bean.getImageUrl())
                .fitCenter()
                .into(image_url);
        Glide.with(this)
                .load(bean.getUserAvatar())
                .asBitmap()
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                        RoundedBitmapDrawable circularBitmapDrawable =
                                RoundedBitmapDrawableFactory.create(getResources(), resource);
                        circularBitmapDrawable.setCircular(true);
                        user_avatar.setImageDrawable(circularBitmapDrawable);
                    }
                });
        user_name.setText(bean.getUserName() + "");
        agree.setText(bean.getLikeCt() + "");
    }
}



